/*
 * Copyright (C) 2022 KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <https://www.gnu.org/licenses/>.
 */

#ifndef LAUNCHERITEM_H
#define LAUNCHERITEM_H

#include <QObject>
#include <QAbstractListModel>
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
#include <QtQml/qqml.h>
#endif

struct LauncherItemPrivate;
class LauncherItem : public QObject
{
    Q_OBJECT
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
    QML_ELEMENT
#endif
    Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
    Q_PROPERTY(int id READ id WRITE setId NOTIFY idChanged)
    Q_PROPERTY(int type READ type WRITE setType NOTIFY typeChanged)
    Q_PROPERTY(int pageIndex READ pageIndex WRITE setPageIndex NOTIFY pageIndexChanged)
    Q_PROPERTY(QString icon READ icon WRITE setIcon NOTIFY iconChanged)
    Q_PROPERTY(QString desktopFile READ desktopFile WRITE setDesktopFile NOTIFY desktopFileChanged)
    Q_PROPERTY(QList<int> categories READ categories WRITE setCategories NOTIFY categoriesChanged)
    Q_PROPERTY(int location READ location WRITE setLocation NOTIFY locationChanged)
    Q_PROPERTY(int rowSpan READ rowSpan WRITE setRowSpan NOTIFY rowSpanChanged)
    Q_PROPERTY(int columnSpan READ columnSpan WRITE setColumnSpan NOTIFY columnSpanChanged)
    Q_PROPERTY(int state READ state WRITE setState NOTIFY stateChanged)
    Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectedChanged)
    Q_PROPERTY(bool appOpen READ appOpen WRITE setAppOpen NOTIFY appOpenChanged)
    Q_PROPERTY(int windowId READ windowId WRITE setWindowId NOTIFY windowIdChanged)
    Q_PROPERTY(bool nameVisible READ nameVisible WRITE setNameVisible NOTIFY nameVisibleChanged)
    Q_PROPERTY(QAbstractListModel * model READ model WRITE setModel NOTIFY modelChanged)
    Q_PROPERTY(QString qmlFile READ qmlFile WRITE setQmlFile NOTIFY qmlFileChanged)
    Q_PROPERTY(bool uninstallable READ uninstallable WRITE setUninstallable NOTIFY uninsatllableChanged)
    Q_PROPERTY(bool titleEditable READ titleEditable WRITE setTitleEditable NOTIFY titleEditableChanged)
    Q_PROPERTY(bool containerEditable READ containerEditable WRITE setContainerEditable NOTIFY containerEditableChanged)
    Q_PROPERTY(int containerCategory READ containerCategory WRITE setContainerCategory NOTIFY containerCategoryChanged)

public:
    enum ItemType {
        AppIcon = 1,
        Group = 2,
        Container = 4,
        Widget = 8,
        Placeholder = 16,
        AddIcon = 32,
        WindowIcon = 64,
        AllType = 128,
    };
    enum ItemState {
        Normal = 1,
        Editable = 2,
        Selectable = 4,
        Under = 8, // 在拖动的图标的下方
        Popup = 16, // 弹出分组显示
        Dragging = 32
    };
    Q_ENUM(ItemType)
    Q_ENUM(ItemState)

    explicit LauncherItem(QObject *parent = nullptr);
    LauncherItem(const LauncherItem &other);
    ~LauncherItem();
    LauncherItem &operator= (const LauncherItem &other);

    QString name() const;
    void setName(const QString &name);

    int id() const;
    void setId(const int &id);

    int type() const;
    void setType(const int &type);

    int pageIndex() const;
    void setPageIndex(const int &pageIndex);

    QString icon() const;
    void setIcon(const QString &icon);

    QString desktopFile() const;
    void setDesktopFile(const QString &desktopFile);

    QList<int> categories() const;
    void setCategories(const QList<int> &categories);

    int location() const;
    void setLocation(const int &location);

    int rowSpan() const;
    void setRowSpan(const int &rowSpan);

    int columnSpan() const;
    void setColumnSpan(const int &columnSpan);

    int state() const;
    void setState(const int &state);

    bool selected() const;
    void setSelected(bool selected);

    bool appOpen() const;
    void setAppOpen(const bool &appOpen);

    int windowId() const;
    void setWindowId(const int &windowId);

    bool nameVisible() const;
    void setNameVisible(const bool &nameVisible);

    QAbstractListModel *model() const;
    void setModel(QAbstractListModel *model);

    QString qmlFile() const;
    void setQmlFile(const QString &qmlFile);

    bool uninstallable() const;
    void setUninstallable(const bool &uninstallable);

    bool titleEditable() const;
    void setTitleEditable(const bool &editable);

    bool containerEditable() const;
    void setContainerEditable(const bool &editable);

    int containerCategory() const;
    void setContainerCategory(const int &category);

Q_SIGNALS:
    void nameChanged();
    void idChanged();
    void typeChanged();
    void indexChanged();
    void pageIndexChanged();
    void iconChanged();
    void desktopFileChanged();
    void categoriesChanged();
    void locationChanged();
    void rowSpanChanged();
    void columnSpanChanged();
    void stateChanged();
    void selectedChanged();
    void appOpenChanged();
    void windowIdChanged();
    void nameVisibleChanged();
    void modelChanged();
    void qmlFileChanged();
    void uninsatllableChanged();
    void titleEditableChanged();
    void containerEditableChanged();
    void containerCategoryChanged();

private:
    LauncherItemPrivate *p;
};

#endif // LAUNCHERITEM_H
